package com.xbao.controller;

import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.Emp;
import com.xbao.model.EmpOrgRel;
import com.xbao.model.req.EmpReq;
import com.xbao.model.vo.EmpVo;
import com.xbao.service.EmpService;
import com.xbao.service.SnsMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/8/24.
 */
@Api(value = "/emp", tags = "emp")
@RequestMapping(value = "emp")
@Controller
@EnableAutoConfiguration
public class EmpController extends BaseController {
    @Resource
    private EmpService empService;
    @Resource
    private SnsMsgService msgService;

    @ApiOperation(value = "addEmp", notes = "addEmp")
    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ResponseBody
    public CommResult addEmp(@RequestBody CommRequest<EmpReq> empReq) {
        empService.addEmp(empReq.getData());
        return result();
    }

    @ApiOperation(value = "updateEmp", notes = "updateEmp")
    @RequestMapping(value = "update",method = RequestMethod.POST)
    @ResponseBody
    public CommResult updateEmp(@RequestBody CommRequest<Emp> empReq) {
        empService.updateEmp(empReq.getData());
        return result();
    }

    @ApiOperation(value = "empList", notes = "empList")
    @RequestMapping(value = "list",method = RequestMethod.POST)
    @ResponseBody
    public CommResult<List<EmpVo>> empList(@RequestBody CommRequest<EmpReq> empReqCommRequest) {
       List<EmpVo> vos= empService.queryEmpList(empReqCommRequest.getData());
       return new CommResult<List<EmpVo>>(vos);
    }


    @ApiOperation(value = "modifyPwd", notes = "modifyPwd")
    @RequestMapping(value = "updatePwd",method = RequestMethod.POST)
    @ResponseBody
    public void modifyPwd(@RequestBody CommRequest<EmpReq> empReqCommRequest) {
        empService.updatePwd(empReqCommRequest.getData());

    }

    @ApiOperation(value = "register", notes = "register")
    @RequestMapping(value = "register",method = RequestMethod.POST)
    @ResponseBody
    public void register(@RequestBody CommRequest<EmpReq> empReqCommRequest) {
        Emp emp = (Emp) empReqCommRequest.getData();
        empService.addEmp(empReqCommRequest.getData());
    }

    @ApiOperation(value = "queryByTag", notes = "queryByTag")
    @RequestMapping(value = "queryByTag",method = RequestMethod.POST)
    @ResponseBody
    public void queryByTag(@RequestBody CommRequest<EmpReq> empReqCommRequest) {
        Emp emp = (Emp) empReqCommRequest.getData();
        empService.addEmp(empReqCommRequest.getData());
    }


    @ApiOperation(value = "updateempandorg", notes = "updateempandorg")
    @RequestMapping(value = "updateorgandemp",method = RequestMethod.POST)
    @ResponseBody
    public void updateempandorg(@RequestBody CommRequest<EmpReq> empReqCommRequest) {
        Emp emp = (Emp) empReqCommRequest.getData();
        empService.addEmp(empReqCommRequest.getData());
    }


    @ApiOperation(value = "loginByMobile", notes = "loginByMobile")
    @RequestMapping(value = "loginByMobile",method = RequestMethod.POST)
    @ResponseBody
    public CommResult<EmpVo> loginByMobile(@RequestBody CommRequest<EmpReq> empReqCommRequest) {
        EmpVo vo= empService.loginByMobile(empReqCommRequest.getData());
        return new CommResult<EmpVo>(vo);

    }

    @ApiOperation(value = "loginByThrid", notes = "loginByThrid")
    @RequestMapping(value = "loginByThrid",method = RequestMethod.POST)
    @ResponseBody
    public void loginByThrid(@RequestBody CommRequest<EmpReq> empReqCommRequest) {
        empService.loginByThrid(empReqCommRequest.getData());

    }





    @ApiOperation(value = "sendVcode", notes = "sendVcode")
    @RequestMapping(value = "sendVcode",method = RequestMethod.POST)
    @ResponseBody
    public CommResult sendValCode(@RequestBody CommRequest<EmpReq> empReqCommRequest) {
       empService.sendVcode(empReqCommRequest.getData());
        return result();
    }

    @ApiOperation(value = "delete", notes = "delete")
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @ResponseBody
    public CommResult delete(@RequestBody CommRequest<EmpReq> empReqCommRequest) {
        empService.deleteEmp(empReqCommRequest.getData().getId());
        return result();
    }

    public void noPeriodEmps(CommRequest<EmpReq> empReqCommRequest) {
        empService.noPeriodEmps(null);
    }

    @ApiOperation(value = "setSelectRel", notes = "setSelectRel")
    @RequestMapping(value = "setSelectRel",method = RequestMethod.POST)
    @ResponseBody
    public CommResult setSelectRel(@RequestBody CommRequest<EmpOrgRel> empReqCommRequest) {
        empService.selectDefaultRel(empReqCommRequest.getData());
        return result();
    }
}
